<template>
  <div>
    <el-row>
      <el-col :span="3"><el-tag type="success">今日已看诊{{ finish_patient_count }}人</el-tag></el-col>
      <el-col :span="3"><el-tag type="warning">当前有{{ wait_patient_count }}人在排队</el-tag></el-col>
      <el-col :span="18"> </el-col>
    </el-row>
    <el-divider></el-divider>
    <div style="font-size:20px;text-align:left">
      <i class="el-icon-document-checked">患者叫号</i>
    </div>
    <el-divider></el-divider>
    <el-row :gutter="20">
      <el-col :span="6"><el-input v-model="caseNumber" placeholder="请输入患者病历号"></el-input></el-col>
      <el-col :span="6"><el-input v-model="realName" placeholder="请输入患者姓名"></el-input></el-col>
      <el-col :span="2"><el-button @click="select">搜索</el-button></el-col>
      <el-col :span="10"> </el-col>
    </el-row>
    <el-divider></el-divider>
    <el-table
      :data="waitPatient"      style="width: 80%">
      <el-table-column        type="index"     label="编号"        width="80"></el-table-column>
      <el-table-column        prop="realName"        label="患者姓名"        width="180"></el-table-column>
      <el-table-column        prop="caseNumber"        label="患者病历号">      </el-table-column>
      <el-table-column label="操作">
      <template #default="scope">
        <el-button   size="mini" @click="udateState(scope.$index, scope.row)">创建病历</el-button>
        <el-button size="mini" @click="showMsg">跳过</el-button>
        <el-button size="mini" @click="showMsg">叫号</el-button>
      </template>
    </el-table-column>
    </el-table>
    <el-divider></el-divider>
    <el-pagination
        :default-current-page="currPage"

    :page-size="pageSize" :total="totalCount" @current-change="table_change"
    layout="prev, pager, next">
  </el-pagination>
  </div>
</template>
<script>
import {getSessionLoginUser} from '../../util/util'
import {getSessionStorage, setLocalStorage, setSessionStorage} from "@/util/common";
import {ElMessage, ElMessageBox} from "element-plus";
export default {
  data() {
    return {
      currPage:1,
      caseNumber:'',
      realName:'',
      pageSize:5,//每页显示行数
      totalCount:0,//总条数
      finish_patient_count:0,//已经看诊完成人数
      wait_patient_count:0,//等待看诊人数
      employeeId:0,//当前医生的id
      waitPatient: []
    }
  },
  methods:{

    showMsg:function ()
    {
      ElMessage({
        type: "info",
        message:'没有连接终端设备！'
          }
      )
    },

    table_change:function (currPage)
    {
      this.currPage=currPage
      this.select()
    },
    //分页查询
    select:function ()
    {
      let register={
        "caseNumber":this.caseNumber,
        "realName":this.realName,
        "employeeId":this.employeeId
      }
      console.log(register)
      let url=`http://localhost:8092/register/selectstatepage/${this.currPage}`
      this.$axios.post(url,register).then(resp=>{
        this.waitPatient=resp.data.result
        this.totalCount=resp.data.total
        console.log(this.waitPatient)
      }).catch(error=>{
        console.log(error)
      })
    },

    //创建病历
    udateState:function (index, row){
      console.log(index,row)

      ElMessageBox.confirm("真的执行？","提示！",{
        type:"success",
        confirmButtonText:'确定',
        cancelButtonText:'取消'
      }).then(()=>{
        let url='http://localhost:8092/register/updatestate'
        let regist={
          "visitState":"2",
          "id":row.id
        }
        this.$axios.put(url,regist).then(resp=>{
          this.select()
          //把当前要要看病的人保存到session中
          setSessionStorage("patient",row)
          ElMessage({
            type:'success',
            message:'医生诊疗：请到病历首页'
          })
        }).catch(error=>{
          console.log(error)
        })
       // alert('确定')
      }).catch(()=>{
        //alert('取消')
      })
      // if(confirm("真的执行？"))
      // {
      //
      // }
    },
    //今日已看诊0人
    getCurrDateCount:function ()
    {

      let employee={
        "visitState":"3",
        "employeeId":this.employeeId
      }
      let url='http://localhost:8092/physicianpatient/getrowcountregisterstate'
      debugger
      this.$axios.post(url,employee).then(resp=>{
        this.finish_patient_count=resp.data.result
      }).catch(error=>{
        console.log(error)
      })
    },
    //当前有0人在排队
    getCurrDateWaitCount:function ()
    {
      let employee={
        "visitState":"1",
        "employeeId":this.employeeId
      }
      let url='http://localhost:8092/physicianpatient/getrowcountregisterstate'
      this.$axios.post(url,employee).then(resp=>{
        this.wait_patient_count=resp.data.result
      }).catch(error=>{
        console.log(error)
      })
    }
  },
  mounted() {

    this.employeeId=getSessionStorage("userLogin").id
    this.select()
    console.log("id="+this.employeeId)
    this.getCurrDateCount()
    this.getCurrDateWaitCount()
  }
}
</script>